<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/31
 * Time: 15:56
 */
//获取HTTP请求原文
function get_http_row()
{
    $raw = '';
    $raw .= $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\r\n";
//   echo $raw;  //GET /study/get_request_heard.php HTTP/1.1
    foreach ($_SERVER as $index => $item) {
        if (substr($index, 0, 5) == 'HTTP_') {
            $index=substr($index,5);
            $index=str_replace('_','-',$index);
            $raw.=$index.':'.$item."\r\n";

        }
    }
    // (3) 空行
    $raw .= "\r\n";
    // (4) 请求Body
    $raw .= '请求Body:'.file_get_contents('php://input');

    return $raw;
}

echo '<pre>';
print_r(get_http_row());
echo '</pre>';
//结果输出

//GET /study/get_request_heard.php HTTP/1.1
//HOST:localhost
//CONNECTION:keep-alive  Keep-Alive模式（又称持久连接、连接重用）时，Keep-Alive功能使客户端到服 务器端的连接持续有效，当出现对服务器的后继请求时，Keep-Alive功能避免了建立或者重新建立连接。
//CACHE-CONTROL:max-age=0
//ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
//UPGRADE-INSECURE-REQUESTS:1
//USER-AGENT:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
//REFERER:http://localhost/study/get_request_heard.php
//ACCEPT-ENCODING:gzip, deflate, sdch
//ACCEPT-LANGUAGE:zh-CN,zh;q=0.8
//
//请求Body:
$raw_post_data = file_get_contents('php://input', 'r');
echo "-------\$_POST------------------<br/>";
echo var_dump($_POST) . "<br/>";
echo "-------php://input-------------<br/>";
echo $raw_post_data . "<br/>";

//结果输出
//-------$_POST------------------
//array(2) { ["userName"]=> string(3) "111" ["userPass"]=> string(4) "2222" }
//-------php://input-------------
//userName=111&userPass=2222